Skip to content

Conversation

@jessicaKoehnke
Copy link
Contributor

Summary

This is a suggestion on how we could better separate test code from production code.

Issue

We have a lot of forTest methods all over our production code. This could potentially lead to code intended for tests to accidentally be used in production. In my opinion test code and production code should never be mixed.

This solution is inspired by the gradle testFixtures plugin. I added a new source to the application module to more or less achieve the same result as the gradle plugin. All classes defined in the new test-fixtures source can be used in all test sources, but not in the production code sources.

To demonstrate the usage I moved the test data factories touched by #6840 into the new test-fixtures source.

Unit tests

no code added -> no tests needed

Documentation

If we decide to move forward with this, it might be a good idea to update the developer guidelines.

@jessicaKoehnke jessicaKoehnke requested a review from a team as a code owner September 26, 2025 11:28
@jessicaKoehnke jessicaKoehnke added the +Skip Changelog This is not a relevant change for a product owner since last release. label Sep 26, 2025
@codecov
Copy link

codecov bot commented Sep 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.09%. Comparing base (0f62e5e) to head (d0bf6e6).
⚠️ Report is 139 commits behind head on dev-2.x.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6904      +/-   ##
=============================================
- Coverage      72.10%   72.09%   -0.01%     
+ Complexity     19663    19658       -5     
=============================================
  Files           2123     2124       +1     
  Lines          79428    79509      +81     
  Branches        8049     8051       +2     
=============================================
+ Hits           57269    57324      +55     
- Misses         19319    19347      +28     
+ Partials        2840     2838       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jessicaKoehnke jessicaKoehnke added the !Technical Debt Improve code quality, no functional changes. label Sep 26, 2025
@optionsome optionsome requested a review from t2gran September 30, 2025 09:32
t2gran
t2gran previously approved these changes Oct 1, 2025
Copy link
Member

@t2gran t2gran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor comments

FileType type,
DataSource... children
) {
return new ListCompositeDataSource(name, type, Arrays.asList(children));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ListCompositeDataSource can also be moved here because it is not used in production - and I do not see that it would be relevant for production. If so, we could move it back. Not needed for me to approve PR.

/**
* Use this to get a composite data source, bypassing the {@link OtpDataStore}.
*/
public static CompositeDataSource compositeSource(File file, FileType type) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to deprecate this to simplify tests, the next method is much easier to use.


public class GtfsBundleTestFactory {

public static GtfsBundle forTest(File gtfsFile, @Nullable String feedId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that prettier is not configured to format these files. Can you change that?

Copy link
Member

@leonardehrenfried leonardehrenfried left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please configure prettier.

@leonardehrenfried
Copy link
Member

TestVertexLinker can also be moved (and perhaps renamed).

@jessicaKoehnke
Copy link
Contributor Author

I only moved a few classes to demonstrate how it works. I can move more (TestVertexLinker and ListCompositeDataSource were mentioned). Should I do that or will the PR get too messy?

@leonardehrenfried
Copy link
Member

I would be fine with both. It's up to you.

@optionsome optionsome added this to the 2.9 (next release) milestone Oct 7, 2025
@jessicaKoehnke jessicaKoehnke merged commit c9d8a58 into opentripplanner:dev-2.x Oct 7, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

+Skip Changelog This is not a relevant change for a product owner since last release. !Technical Debt Improve code quality, no functional changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants